package com.iflytek.sbd.resolver;

import com.iflytek.sbd.annotation.ParameterCheck;
import org.springframework.core.MethodParameter;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.support.WebDataBinderFactory;
import org.springframework.web.context.request.NativeWebRequest;
import org.springframework.web.method.support.HandlerMethodArgumentResolver;
import org.springframework.web.method.support.ModelAndViewContainer;

/**
 * @program: sbd
 * @description: 方法参数解析器 配合@RequestParam使用
 * @author: 陈英俊
 * @create: 2022-01-10 10:13
 */
@Component
public class ParameterResolver implements HandlerMethodArgumentResolver {

    /**
     * 满足条件返回true,进入下面的方法
     *
     * @param parameter
     * @return
     */
    @Override
    public boolean supportsParameter(MethodParameter parameter) {
        return parameter.hasParameterAnnotation(ParameterCheck.class);
    }

    @Override
    public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception {
        return null;
    }
}
